﻿using SudukuSolver_Mvvm.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SudukuSolver_Mvvm.Services;

/// <summary>
/// 数独示例
/// </summary>
public static class GetExamples
{
    private static Random random = new Random();

    /// <summary>
    /// 简单数独
    /// </summary>
    public static List<int[][]> Level1 { get; set; }

    /// <summary>
    /// 中等数独
    /// </summary>
    public static List<int[][]> Level2 { get; set; }

    /// <summary>
    /// 困难数独
    /// </summary>
    public static List<int[][]> Level3 { get; set; }

    static GetExamples()
    {
        InitLevel1();
        InitLevel2();
        InitLevel3();
    }

    private static void InitLevel1()
    {
        Level1 = new List<int[][]>();
        Level1.Add(new int[9][]
        {
            new int[9]{ 0,1,7,  0,0,2,  0,0,3 },
            new int[9]{ 8,0,0,  0,0,0,  5,0,7 },
            new int[9]{ 0,0,4,  3,7,0,  0,8,0 },

            new int[9]{ 0,0,0,  7,4,0,  0,0,5 },
            new int[9]{ 7,2,0,  0,9,0,  4,0,0 },
            new int[9]{ 3,0,0,  5,0,0,  0,6,0 },

            new int[9]{ 4,3,8,  0,0,1,  0,0,0 },
            new int[9]{ 0,0,0,  0,0,7,  8,1,0 },
            new int[9]{ 0,0,6,  2,0,4,  0,5,0 }
        });

        Level1.Add(new int[9][]
        {
            new int[9]{ 0,7,0,  0,0,0,  0,5,9 },
            new int[9]{ 8,0,0,  0,2,5,  0,0,6 },
            new int[9]{ 0,5,9,  6,7,0,  0,0,0 },

            new int[9]{ 7,0,5,  4,0,0,  1,0,0 },
            new int[9]{ 0,6,0,  0,0,2,  9,0,0 },
            new int[9]{ 0,0,2,  0,0,1,  0,0,3 },

            new int[9]{ 3,0,7,  0,0,0,  0,9,0 },
            new int[9]{ 9,2,0,  0,0,0,  8,1,0 },
            new int[9]{ 0,0,0,  2,9,4,  0,6,0 }
        });

        Level1.Add(new int[9][]
        {
            new int[9]{ 0,3,2,  0,1,9,  0,0,0 },
            new int[9]{ 1,0,0,  0,6,0,  5,0,5 },
            new int[9]{ 6,0,0,  0,0,0,  4,9,0 },

            new int[9]{ 0,0,0,  2,7,0,  1,0,9 },
            new int[9]{ 9,2,0,  0,0,0,  0,0,3 },
            new int[9]{ 5,0,1,  0,0,8,  7,0,0 },

            new int[9]{ 0,0,0,  8,0,4,  0,1,0 },
            new int[9]{ 0,5,6,  0,0,7,  0,0,0 },
            new int[9]{ 0,1,0,  6,0,0,  9,7,2 }
        });
    }

    private static void InitLevel2()
    {
        Level2 = new List<int[][]>();
        Level2.Add(new int[9][]
        {
            new int[9]{ 4,0,0,  6,7,0,  5,0,0 },
            new int[9]{ 0,7,0,  0,5,0,  1,6,0 },
            new int[9]{ 0,0,6,  2,0,0,  0,4,0 },

            new int[9]{ 0,6,0,  0,0,0,  0,2,4 },
            new int[9]{ 0,0,0,  7,0,1,  0,0,9 },
            new int[9]{ 0,9,3,  0,0,8,  0,0,0 },

            new int[9]{ 2,0,0,  9,0,6,  0,1,0 },
            new int[9]{ 7,0,0,  0,8,0,  0,0,6 },
            new int[9]{ 0,0,9,  0,0,0,  2,0,5 }
        });

        Level2.Add(new int[9][]
        {
            new int[9] { 8,0,5,  0,0,2,  3,0,0 },
            new int[9] { 0,0,3,  0,0,7,  8,0,0 },
            new int[9] { 2,0,0,  0,8,6,  0,0,1 },

            new int[9] { 0,5,1,  0,0,0,  0,4,0 },
            new int[9] { 0,0,0,  1,9,4,  0,8,0 },
            new int[9] { 0,2,0,  7,0,0,  6,0,0 },

            new int[9] { 5,3,9,  0,0,0,  0,0,0 },
            new int[9] { 0,0,0,  2,7,0,  0,0,6 },
            new int[9] { 0,0,0,  0,3,0,  0,5,8 }
        });

        Level2.Add(new int[9][]
        {
            new int[9] { 0,3,0,  0,1,6,  0,0,2 },
            new int[9] { 6,8,0,  0,0,7,  0,0,0 },
            new int[9] { 0,0,0,  0,0,2,  3,7,0 },

            new int[9] { 0,0,0,  7,0,0,  0,0,3 },
            new int[9] { 0,0,7,  0,6,0,  0,2,4 },
            new int[9] { 5,2,0,  4,0,0,  0,8,0 },

            new int[9] { 0,0,0,  5,3,0,  7,0,0 },
            new int[9] { 4,0,3,  0,0,0,  2,9,0 },
            new int[9] { 0,0,5,  0,7,0,  0,0,8 }
        });
    }

    private static void InitLevel3()
    {
        Level3 = new List<int[][]>();
        Level3.Add(new int[9][]
        {
            new int[9] { 0,5,2,  8,0,0,  0,0,3 },
            new int[9] { 0,6,0,  0,0,0,  8,1,0 },
            new int[9] { 0,0,0,  3,0,0,  2,0,0 },

            new int[9] { 0,8,0,  0,3,0,  0,0,0 },
            new int[9] { 0,0,0,  0,0,4,  0,0,5 },
            new int[9] { 5,0,7,  0,0,0,  3,0,0 },

            new int[9] { 8,0,1,  0,0,7,  9,0,6 },
            new int[9] { 0,2,0,  0,0,8,  0,0,7 },
            new int[9] { 0,0,0,  9,6,0,  0,8,0 }
        });

        Level3.Add(new int[9][]
        {
            new int[9] { 0,0,0,  0,4,0,  0,5,0 },
            new int[9] { 7,5,0,  0,8,0,  0,3,0 },
            new int[9] { 0,3,0,  7,1,0,  0,0,2 },

            new int[9] { 6,0,7,  0,0,0,  0,4,0 },
            new int[9] { 0,0,0,  0,3,0,  0,2,0 },
            new int[9] { 0,4,0,  0,0,6,  0,0,1 },

            new int[9] { 0,0,8,  0,0,4,  0,0,0 },
            new int[9] { 0,0,0,  0,0,3,  9,0,0 },
            new int[9] { 9,0,0,  0,0,0,  6,0,0 }
        });

        Level3.Add(new int[9][]
        {
            new int[9] { 0,8,0,  0,0,0,  7,0,0 },
            new int[9] { 0,0,0,  0,4,3,  0,0,1 },
            new int[9] { 4,0,7,  0,0,0,  0,6,0 },

            new int[9] { 2,9,0,  0,0,0,  0,0,6 },
            new int[9] { 0,0,0,  4,0,7,  0,5,0 },
            new int[9] { 0,0,3,  0,6,0,  0,0,0 },

            new int[9] { 0,2,6,  0,5,9,  0,0,7 },
            new int[9] { 0,0,0,  6,0,0,  8,0,0 },
            new int[9] { 0,0,5,  8,3,0,  0,9,0 }
        });
    }

    public static int[][] GetRandom(Level level)
    {
        List<int[][]> sudus = null;
        switch (level)
        {
            case Level.中等:
                sudus = Level2;
                break;
            case Level.困难:
                sudus = Level3;
                break;
            case Level.简单:
            default:
                sudus = Level1;
                break;
        }

        int index = random.Next(0, sudus.Count);
        return sudus[index];
    }
}